# General variables
DEBUG=yes
RELNAME=AMazeRing

# Compilator Definitions

export CXX = g++
export CC = gcc
export LD = g++

export DEFINES += -O2
export DEFINES_DBG += -ggdb -D_DEBUG

export CXXFLAGS += -Wall -Wextra -pedantic -ansi -I ./include/ -I. -Isources
export CFLAGS += -Wall -Wextra -pedantic -ansi -I ./include/ -I. -Isources
export LDFLAGS += -L./lib/ -lsfml-window -lsfml-graphics -lsfml-audio -lsfml-system

ifeq ($(DEBUG),yes)
	CXXFLAGS += $(DEFINES_DBG)
	CFLAGS += $(DEFINES_DBG)
endif

# Folders settings

# Compilation Rules
ifeq ($(DEBUG),yes)
	EXEC = ./bin/Debug/$(RELNAME)
else
	EXEC = ./bin/Release/$(RELNAME)
endif

RENDERER=sources/Renderer/Renderer.o sources/Renderer/SpriteManager.o sources/Renderer/AnimatedSprite.o 
LEVEL=sources/Game/Level/LevelLoader.o sources/Game/Level/Level.o
GAMEOBJECTS=sources/Game/Objects/GameObject.o sources/Game/Objects/Player.o sources/Game/Objects/Tile.o
GAME=sources/Game/Game.o sources/Game/Editor.o sources/Game/World.o

OBJECTS = $(RENDERER) $(GAME) $(LEVEL) $(GAMEOBJECTS) sources/Utils.o sources/ArgumentParser.o sources/GameOption.o  sources/main.o


all: $(EXEC)
ifeq ($(DEBUG),yes)
	@echo "\033[35m=== Compilation in debug mode\t\t\tDONE\033[0m"
else
	@echo "\033[36m=== Compilation in release mode\t\t\tDONE\033[0m"
endif

%.o: %.cpp *.hpp
	@echo "\033[34m$(CXX) $< -> $@\033[0m";\
	$(CXX) $(CXXFLAGS) -c $< -o $@

%.o: %.cpp *.h
	@echo "$(CXX) $< -> $@\033[0m";\
	$(CXX) $(CXXFLAGS) -c $< -o $@

%.o: %.c *.h
	@echo "$(CC) $< -> $@\033[0m";\
	$(CC) $(CFLAGS) -c $< -o $@

$(EXEC): $(OBJECTS)
	@echo "\033[32m$(LD) ($(OBJECTS)) -> $(EXEC)\033[0m";
ifeq ($(DEBUG),yes)
	mkdir -p bin/Debug
else
	mkdir -p bin/Release
endif
	$(LD) $(LDFLAGS) $(OBJECTS) -o $@

.PHONY: clean mrproper

clean:
	@echo "\033[31m"
	rm -rfv $(OBJECTS)
	@echo "\033[0m"

mrproper: clean
	@echo "\033[31m"
	rm -rfv $(EXEC)
	@echo "\033[0m"

run:
ifeq ($(DEBUG),yes)
	LD_LIBRARY_PATH=./lib ./bin/Debug/$(RELNAME)
else
	LD_LIBRARY_PATH=./lib ./bin/Release/$(RELNAME)
endif

publish:
	mkdir -p /tmp/AMazeRing
	svn export http://a-maze-ring.googlecode.com/svn/trunk/ /tmp/AMazeRing_sources
#	cp Release/AMazeRing.exe /tmp/AMazeRing
	cp -r /tmp/AMazeRing_sources/data /tmp/AMazeRing
	cp -r /tmp/AMazeRing_sources/*.dll /tmp/AMazeRing

	


